package main

import (
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/net/ghttp"
	"github.com/gogf/gf/v2/util/gconv"
	"time"
)

func main() {
	s := g.Server()

	s.BindHandler("/sse", func(r *ghttp.Request) {
		r.Response.Header().Set("Content-Type", "text/event-stream")
		r.Response.Header().Set("Cache-Control", "no-cache")

		for i := 1; ; i++ {
			if err := r.Response.WriteFlushText(
				"data: " + gconv.String(i) + "\n\n",
			); err != nil {
				return
			}

			time.Sleep(1 * time.Second)
		}
	})

	s.Run()
}
